package com.dome.backtemplate.verification;

import cn.hutool.dfa.SensitiveUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Description 敏感词验证
 * @Author 小乌龟
 * @Date 2023/3/7 18:53
 */
public class IsSensitiveWordValidation implements ConstraintValidator<IsSensitiveWord, String> {
    @Override
    public void initialize(IsSensitiveWord constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }


    @Override
    public boolean isValid(String content, ConstraintValidatorContext constraintValidatorContext) {
        //hutool 敏感词查询 是否包含敏感词
        return !SensitiveUtil.containsSensitive(content);
    }
}